package czStvDpds;

import czStvDpds.centrallogic.EventAbsorber;
import czStvDpds.centrallogic.Logic;
import czStvDpds.collisionGeometry.HitBoxInitializer;
import czStvDpds.graphics3D.Drawing;
import czStvDpds.graphics3D.GraphicsIndex;
import czStvDpds.i18n.Internationalization;
import czStvDpds.input.InputHandler;
import czStvDpds.mapmanagment.Map;
import czStvDpds.mapmanagment.MapLoader;
import czStvDpds.movement.CollisionManager;
import czStvDpds.network.ServerManager;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Spouštěcí sekvence hry.
 *
 * @author Jirka
 */
public class Launcher extends LauncherBase {

    public static void main(String[] args) {
        new Launcher().run();
    }

    @Override
    public void initLibs() {
        String separator = System.getProperty("file.separator");
        System.setProperty("org.lwjgl.librarypath", System.getProperty("user.dir") + separator + "target" + separator + "natives");
    }

    @Override
    public void initResources() {
        logger.info("Hello World!");
        Internationalization.setLocale("cs", "CZ");
    }
    Drawing draw;
    Logic logic;
    //TESTY - drawing2D a draw = GameWindow.getDrawing(); //Původně: draw = Window.getDrawing()
    //Drawing2D draw;

    @Override
    public void initGraphics() {
        draw = GraphicsIndex.getDrawing();
        draw.setWindowState(Drawing.SCENE_GAME);
    }

    @Override
    public void initLogic() {
        logic = new Logic();
    }

    @Override
    public void initNetwork() {
        try {
            //síť
            ServerManager serverManager = new ServerManager(InetAddress.getLocalHost(), logic);
        } catch (UnknownHostException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void initInput() {
        EventAbsorber eventAbsorber = new EventAbsorber(logic);
        InputHandler inputHandler = GraphicsIndex.getInputHandler();
        inputHandler.addLWJGLKeyListener(eventAbsorber);
        inputHandler.addLWJGLMouseListener(eventAbsorber);
    }

    /**
     * Jen pro debugování, později se mapy budou pravděpodobně inicalizovat
     * jinde
     *
     * @throws IOException
     */
    @Override
    public void initMaps() throws IOException {
        Map testMap = MapLoader.loadMap("resources/maps/spawnPointTest.txt");
        draw.setMapData(testMap);
        HitBoxInitializer.getHitBoxInitializer().loadHitBoxFiles();
        CollisionManager.getCollisionManager().setMap(testMap);
    }
}
